package cn.cai.controller;


import cn.cai.commonUtils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import cn.cai.service.VideoService;

/**
 * 视频接口的控制层
 */
@RestController
@RequestMapping("/eduvideo")
@CrossOrigin
@Api(value = "教学视频的接口控制层",tags = "真实视频的信息操作")
public class VideoController {

    @Autowired
    private VideoService videoService;
    /**
     * 视频的上传，上传视频文件，向minio服务器中添加视频文件（文件名为随机生成的唯一id），并将信息存储进数据库
     * --TODO 视频的上传并将信息添加进数据库
     */
    @PostMapping("/uploadVideo")
    @ApiOperation(value = "视频文件的上传")
    public Result uploadVide(@ApiParam(name = "uploadFile",value = "上传的文件",required = true)
                                        @RequestBody MultipartFile uploadFile){
        String url = videoService.uploadVideo(uploadFile);
        return Result.success().data("url",url);
    }

    @DeleteMapping("/deleteVideo/{videoId}")
    @ApiOperation(value = "视频文件的删除")
    public Result deleteVideo(@ApiParam(name = "videoId",value = "要删除的视频ID",required = true)
                                          @RequestParam(value = "videoId") String videoId){
        videoService.deleteVideoById(videoId);

        return Result.success().data("msg","视频删除成功");
    }
}
